package stream;

import pojo.UserInfo;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;


public class FilterList {
    public static void main(String[] args) {
        ArrayList<UserInfo> list = new ArrayList();
        list.add(new UserInfo(1, "张三", 1));
        list.add(new UserInfo(2, "李四", 2));
        list.add(new UserInfo(3, "王五", 3));
        list.add(new UserInfo(3, "赵六", 4));
        List<UserInfo> collect = list.stream()
                // 保留isDelete > 2 的元素
                .filter(userInfo -> userInfo.getIsDelete() > 2)
                .collect(Collectors.toList());
        collect.forEach(k -> {
            System.out.println(String.format("name=%s,isDelete=%s", k.getName(), k.getIsDelete()));
        });
        // 只获取保留元素ID列表
        LinkedList<Integer> collect1 = collect.stream()
                .map(UserInfo::getId)
                .collect(Collectors.toCollection(LinkedList::new));
        System.out.println("获取到的ID列表是" + collect1);
    }
}
